package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.health.mapper.LoginMapper;
import com.itheima.health.pojo.LoginDto;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;

    @Override
    public Member login(LoginDto loginDto) {
        LambdaQueryWrapper<Member> wrapper= new LambdaQueryWrapper<>();
        wrapper.eq(Member::getPhoneNumber,loginDto.getTelephone());

        Member member = loginMapper.selectOne(wrapper);
        if(member==null){
            //表示第一次登录添加道表里返回
            Member member1 = new Member();
            member1.setPhoneNumber(loginDto.getTelephone());
            loginMapper.insert(member1);
            return member1;
        }
        //表示用户登录过直接返回
        return member;
    }
}
